package de.java.shortys.myhome.fuelmonitor.model;

import java.util.List;
import java.util.Observable;

public class FuelMonitor extends Observable implements IFuelMonitorModelService {

	private List<IFuelFilling> fuelFillings;

	public FuelMonitor() {
		setChanged();
	}

	@Override
	public void create(IFuelFilling fuelFilling) {
		fuelFillings.add(fuelFilling);
		notifyObservers(fuelFilling);
		setChanged();
	}

	@Override
	public void delete(IFuelFilling fuelFilling) {
		fuelFillings.remove(fuelFilling);
		notifyObservers();
		setChanged();
	}

	@Override
	public List<IFuelFilling> read() {
		return fuelFillings;
	}

	public void setFuelFillings(List<IFuelFilling> fuelFillings) {
		this.fuelFillings = fuelFillings;
	}

	@Override
	public void update(IFuelFilling fuelFilling) {
		fuelFillings.set(fuelFillings.indexOf(fuelFilling), fuelFilling);
		notifyObservers(fuelFilling);
		setChanged();
	}

}
